package com.davies.learn.jbv.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.CompletableFuture;

/**
 * @author davies
 * @date 2023/8/10 11:02
 */
@RestController
public class SleepController {


    @Autowired(required = false)
    private WebClient webClient;



    @GetMapping("/")
    public CompletableFuture<String> hello(){
        String beginTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
       return  webClient.get().uri("http://localhost:3000/api")
                .retrieve()
                .bodyToMono(String.class)
                .map(time -> beginTime + " " + time)
                .toFuture();


    }
}
